package com.hualan.sfzy.controller;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.model.entity.CourseClassify;
import com.hualan.sfzy.service.CourseClassifyService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/courseClassify")
public class CourseClassifyController {
    @Autowired
    private CourseClassifyService courseClassifyService;

    @PostMapping()
    public Result add(@RequestBody CourseClassify courseClassify){
        System.out.println(courseClassify);
        int i=  courseClassifyService.add(courseClassify);
        if(i>0){
            return Result.success();
        }
        return Result.error("添加失败");

    }
    @PutMapping()
    public Result update(@RequestBody CourseClassify courseClassify){
        int i=courseClassifyService.edit(courseClassify);
        if(i>0){
            return Result.success();
        }
        return Result.error("修改失败");
    }
    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") int id){
        int i=courseClassifyService.remove(id);
        if(i>0){
            return Result.success();
        }
        return Result.error("删除失败");
    }
    @DeleteMapping()
    public Result deleteAll(@RequestParam Integer[] ids){
        int i=courseClassifyService.removeBatch(ids);
        if(i>0){
            return Result.success();
        }
        return Result.error("删除失败");

    }
    @GetMapping("/all")
    public Result getAll(@RequestParam (value ="pageNum" ,defaultValue = CommonConstant.PAGE_NUM_DEFAULT)Integer pageNum,
                         @RequestParam (value = "pageSize" ,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT)Integer pageSize,
                         CourseClassify courseClassify){
        Map<String,Object> map=courseClassifyService.findPage(pageNum,pageSize,courseClassify);

            return Result.success(map);



    }
    @GetMapping()
    public Result get(@RequestParam Integer id){
        CourseClassify courseClassify=courseClassifyService.findById(id);

            return Result.success(courseClassify);

    }









}
